
window.box = new LightBox();
//box.addMsgWindow();

document.observe("dom:loaded", initLoaded);

function initLoaded()
{
	//$('second_hide_close').hide();

	window.onresize = function()
	{
		$$('.overlay').each(function (elt)
		{
			elt.setStyle({
				height:document.viewport.getHeight() + 'px'
			});
		});


		$$('.mask').each(function (elt)
		{
			if (elt == document.body)
			{
				var pg = getPageSize();

				$('m_' + elt.id).setStyle({
					width:pg[0] + "px",
					height:pg[1] + "px"
				});
			}
		});
	}

	window.T = new Tip();

	//Event.observe(window, 'scroll', onscrollOpration, false);
	window.M = new Message('MHXZ', _('wrong'), true);
}

document.observe('dom:loaded', function(){
	if (Prototype.Browser.IE)
	{
		document.execCommand('BackgroundImageCache', false, true);
	}

	//取得用户停留点,放入MAIN.php
	//get_user_mapid_obj.send();

	new Notifier(1000 * 300);
	document.observe('state:idle', onIdle).observe('state:active', onActive);
	
	function onIdle(e)
	{
		console.info('onIdle');
		//$(document.body).setOpacity(0.2);
		//$('wrapper').setOpacity(0.2);
		active = false;
	}

	function onActive(e)
	{
		//console.info('onActive');
		//console.info(e.memo);
		if (active)
		{
			active = true;
		}
		else
		{
			active = true;
			//$(document.body).setOpacity(1);
			//$('wrapper').setOpacity(1);
		}
	}
});



//tabs functions， 所有的可以通过一段js配置生成。  为了每个操作方便， tabs用html生成， 不用js配置
var ctl_rows = 
[
	{ctl:'Main_Index', id:'ajax_test', cache:0, p:{met:'ajax'}},
	{ctl:'Main_Index', id:'ajax_json', p:{met:'json'}}
]

ctl_rows.each(function(s, index)
{
	var id;
	var p;
	var c;

	if (Object.isUndefined(s.id))
	{
		id = s.ctl;
	}
	else
	{
		id = s.id;
	}


	if (Object.isUndefined(s.p))
	{
		p = '{}';
	}
	else
	{
		p = Object.toJSON(s.p);
	}

	if (Object.isUndefined(s.cache))
	{
		c = '';
	}
	else
	{
		c = ', cache:' + s.cache;
	}

	var s = 'window.' + id + ' = new DAjax("' + index_url + '?ctl=' + s.ctl + '", {form:{ messageState:"load", lbType:"o"}, logic: {id:"' + id + '",  typ:"o" ' + c +  '}, queryKey:' + p + '});';

	eval(s);
}); 

window.main_index = new DAjax(index_url + "?ctl=Main_Index", {form:{ messageState:"load", lbType:"o"}, logic: {id:"main_index",  typ:"e" }, queryKey:{"met":"hello"}});



ajax_json.onSuccess   = function()
{
	box.showMsgBox(Object.toJSON(this.responseData), 'o');
}


ajax_test.onSuccess   = function()
{
	//$('skill_tree_a').writeAttribute('tree', '');
}

var city_overview = new DAjax(index_url + "?ctl=city", 
{
	form:{method:"get",  messageState:'true', lbType:'o' }, 
	logic: {id:"city_overview", act:"overview",  typ:"e"}
});

city_overview.onSuccess   = function()
{
	//box.showMsgBox(this.responseData, 'o');
}

city_overview.onError   = function()
{
	//box.showMsgBox(this.errorMessage);
}



var msg_pack_t = new DAjax("/11", 
{
	form:{method:"get",  messageState:'true', lbType:'o' }, 
	logic: {id:"city_overview", act:"overview",  typ:"e"}
});

msg_pack_t.onSuccess   = function()
{
	box.showMsgBox(Object.toJSON(this.responseData), 'o');

	console.info(this.responseData);

                            //var byteArray = _ie ? toByteArrayIE(this.responseData)
                                            //: toByteArray(this.responseData);
                            //var data = msgpackunpack(byteArray);
							//console.info(data)
	//console.info( msgpack.unpack(data));

}

msg_pack_t.onError   = function()
{
	//box.showMsgBox(this.errorMessage);
}
